<template>
  <div style="height: 400px">
    <el-row>
      <el-button
        icon="el-icon-refresh"
        plain
        type="primary"
        @click="saveData()"
        :disabled="!zIsOpenData"
        >保存</el-button
      >
      <el-button plain type="warning" @click="openData()">刷新</el-button>
      <el-button plain type="danger" @click="closeForm()">关闭</el-button>
    </el-row>
    <div style="height: 15px"></div>
    <el-form
      ref="form"
      :model="FAccount"
      label-width="80px"
      label-position="left"
    >
      <el-row>
        <el-col :span="11">
          <el-form-item label="微信AppID">
            <el-input
              v-model="FAccount.FAppID"
              placeholder="必需的参数"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2"> </el-col>
        <el-col :span="11">
          <el-form-item label="微信密钥">
            <el-input
              v-model="FAccount.FAppSecret"
              placeholder="必需的参数"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="11">
          <el-form-item label="消息Token">
            <el-input
              v-model="FAccount.FMessageToken"
              placeholder="微信回调Url设置的Token"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2"> </el-col>
        <el-col :span="11">
          <el-form-item label="消息密钥">
            <el-input
              v-model="FAccount.FMessageEncodingAESKey"
              placeholder="微信回调信息密钥"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="微信AccessToken" label-width="160px">
        <el-input
          v-model="FAccount.FAccessToken"
          readonly
          ReadOnlyColor
        ></el-input>
      </el-form-item>
      <el-form-item label="AccessToken刷新时间" label-width="160px">
        <el-input
          v-model="FAccount.FAccessTokenLastTime"
          readonly
          ReadOnlyColor
        ></el-input>
      </el-form-item>
      <el-form-item label="微信网页授权URL" label-width="160px">
        <el-input v-model="FAccount.FGetAuthorCodeUrl"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from "vue-class-component";
import BaseForm from "../BaseForm";
import WXAdminApi, { TWXAccount } from "@/baselib/module/weixin/WXAdminApi";

//配合着用
@Options({
  data() {},
  methods: {},
})
export default class TFormWXAccountEdit extends BaseForm {
  public FAccount: TWXAccount = new TWXAccount();
  public created() {
    this.zIsOpenData = false;
    this.FAccount = this.zContextParams.wxAccount;
    this.openData();
  }
  private async openData() {
    this.zIsOpenData = false;
    if (this.$myStrHelper.stringIsEmptyYW(this.FAccount.FAccountID)) {
      //新建不需要去打开数据
      this.zIsOpenData = true;
      return;
    }
    //编辑重新打开数据
    let lResult = await WXAdminApi.GetWXAccountByID(
      this.FAccount.FAccountID
    );
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FAccount = lResult.resultData;
    this.$myMsgHelp.msgHintAutoClose("获取数据成功");
    this.zIsOpenData = true;
  }
  private async saveData() {
    let lResult = await WXAdminApi.SaveWXAccount(this.FAccount);
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FAccount = lResult.resultData;
    this.$myMsgHelp.msgHintAutoClose("保存成功");
  }
  private closeForm() {
    if (this.zContextOnCall != undefined) {
      this.zContextOnCall("close", this.FAccount);
    }
  }
}
</script>

<style>
</style>